<template>
	<div>
		<main class="login-main">
			<div class="login-logo"><img src="../../static/img/LOGO.png"/></div>
			<div class="login-from">
				<label>
					<input type="text" placeholder="请输入用户名" v-model="username"/>
				</label>
				<label>
					<input type="password"  placeholder="请输入密码" v-model="password"/>
				</label>
			</div>
			<div class="login-btn">
				<a href="#" @click="login">登录</a>
			</div>
			<div class="link-reg">
				<router-link to="/reg">还没账号?</router-link>
			</div>
			<div class="link-home">
				<a href="#">暂不登录</a>
			</div>
		</main>
	</div>
</template>

<script>
	import {Toast} from "mint-ui"
	export default{
		data(){
			return{
				username:'',
				password:''
			}
		},
		methods:{
			login(){
				if(this.username==""){
					Toast({
						message:"用户名不能为空",
						position:"top", //显示的地方是上面
						duration:3000   //显示时间为3s
					});
					return
				}
				if(this.password==""){
					Toast({
						message:"密码不能为空",
						position:"top",
						duration:3000   //显示时间为3s
					});
					return
				}
				this.$http.post("http://film.glkjjt.com/Api/Login",this.qs.stringify({
					UserName:this.username,
					Password:this.password
				}))
				.then(res=>{
					localStorage.setItem("tokeID",res.config.data)
					console.log(res)
					Toast({
						message:"登录成功",
						position:"top",  
						duration:3000 
					});
					this.$router.push("/home")
				})
				.catch(err=>{
					if(err.response.status==401){
						Toast({
							message:"无法访问",
							position:"top",  
							duration:3000 
					    });
					}
					if(err.response.status==404){
						Toast({
							message:"网络请求失败，请稍后",
							position:"top",  
							duration:3000 
					    });
					}
				})
			}
		}
	}
</script>

<style>
</style>